<?php

namespace App\Notifications;

use App\Models\Order;

class OrderStatusChanged extends BaseNotification
{
    public function __construct(Order $order, string $oldStatus = null, string $newStatus = null)
    {
        $this->category = 'order';
        $this->title = '订单状态更新';
        
        // 根据状态变化生成不同的内容
        if ($oldStatus && $newStatus) {
            $statusText = $this->getStatusText($newStatus);
            $this->content = "您的订单 {$order->order_number} 状态已从「{$this->getStatusText($oldStatus)}」更新为「{$statusText}」";
        } else {
            $this->content = "您的订单 {$order->order_number} 状态已更新为：{$order->status_text}";
        }
        
        $this->actionUrl = route('order.show', $order->order_number);
    }
    
    private function getStatusText(string $status): string
    {
        $statusMap = [
            'pending' => '待处理',
            'processing' => '处理中',
            'shipped' => '已发货',
            'delivered' => '已送达',
            'cancelled' => '已取消',
            'refunded' => '已退款',
        ];
        
        return $statusMap[$status] ?? $status;
    }
}
